package com.sumansoul.lodingwindowdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.android.tu.loadingdialog.LoadingDailog;
import com.sumansoul.lodingwindowdemo.utils.ALLAlertLoadingDialog;
import com.sumansoul.lodingwindowdemo.utils.AlertAnimationLoading;
import com.sumansoul.lodingwindowdemo.utils.AlertLoadingDialog;
import com.sumansoul.lodingwindowdemo.utils.CustomerLoadingDailog;

public class MainActivity extends AppCompatActivity {

    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    private Button btn5;
    private Button btn6;
    private Button btn7;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1 = findViewById(R.id.btn1);
        btn2 = findViewById(R.id.btn2);
        btn3 = findViewById(R.id.btn3);
        btn4 = findViewById(R.id.btn4);
        btn5 = findViewById(R.id.btn5);
        btn6 = findViewById(R.id.btn6);
        btn7 = findViewById(R.id.btn7);
        initData();
    }

    private void initData() {

        /**
         * 1. 框架加载框
         */
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LoadingDailog.Builder loadBuilder=new LoadingDailog.Builder(MainActivity.this)
                        .setMessage("加载中...")
                        .setCancelable(true)
                        .setCancelOutside(true);
                LoadingDailog dialog=loadBuilder.create();
                dialog.show();

            }
        });


        /**
         * 2.自定义加载框
         */
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CustomerLoadingDailog.Builder loadBuilder=new CustomerLoadingDailog.Builder(MainActivity.this)
                        .setMessage("正在加载中...")
                        .setCancelable(true)
                        .setCancelOutside(false);
                CustomerLoadingDailog dialog=loadBuilder.create();
                dialog.show();
            }
        });


        /**
         * 3.Android原生加载框（防止闪屏）
         */
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                 final AlertLoadingDialog dialog = new AlertLoadingDialog(MainActivity.this);

                dialog.showDialog("努力加载中...");
                dialog.setCanceledOnTouchOutside(false);
                //sleep设置的是时长
                //sleep设置的是时长
//                new Handler().postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        dialog.hideDialog();
//                    }
//                },1000) ;
            }
        });


        /**
         * 4.菊花加载框（防止闪屏）
         */
        btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final ALLAlertLoadingDialog dialog = new ALLAlertLoadingDialog(MainActivity.this);

                dialog.showDialog("努力加载中...");
                //dialog.setCanceledOnTouchOutside(true);
            }
        });


        /**
         * 5.Android 动画一
         */
        btn5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertAnimationLoading alertLoading1 = new AlertAnimationLoading(MainActivity.this,  R.layout.base_loading_dialog);
                alertLoading1.setMessage("加载中....");
                alertLoading1.setCanceledOnTouchOutside(true);
                alertLoading1.show();
            }
        });



        /**
         * 6.Android 动画二
         */
        btn6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertAnimationLoading alertLoading1 = new AlertAnimationLoading(MainActivity.this,  R.layout.base_loading_dialog2);
                alertLoading1.setMessage("加载中....");
                alertLoading1.setCanceledOnTouchOutside(true);
                alertLoading1.show();
            }
        });



        /**
         * 7.Android 动画三
         */
        btn7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertAnimationLoading alertLoading1 = new AlertAnimationLoading(MainActivity.this,  R.layout.base_loading_dialog3);
                alertLoading1.setMessage("加载中....");
                alertLoading1.setCanceledOnTouchOutside(true);
                alertLoading1.show();
            }
        });
    }
}
